<?php


 //declare(ticks=1);

use \GatewayWorker\Lib\Gateway;


class Events{

 

    /**
     * onConnect 事件回调
     * 当客户端连接上gateway进程时(TCP三次握手完毕时)触发
     *
     * @access public
     * @param  int       $client_id
     * @return void
     */
    public static function onConnect($client_id){

    }

    /**
     * onWebSocketConnect 事件回调
     * 当客户端连接上gateway完成websocket握手时触发
     *
     * @param  integer  $client_id 断开连接的客户端client_id
     * @param  mixed    $data
     * @return void
     */
    public static function onWebSocketConnect($client_id, $data) { 
        Gateway::bindUid($client_id,$data['get']['user_id']);
        $message['type']='bind';
    	$message['message']='绑定成功';
        Gateway::sendToClient($client_id,json_encode($message));
    }

    /**
     * onMessage 事件回调
     * 当客户端发来数据(Gateway进程收到数据)后触发
     *
     * @access public
     * @param  int       $client_id
     * @param  mixed     $data
     * @return void
     */
    public static function onMessage($client_id, $data)    {
    	// $recive=json_decode($data,true);
    	// $message['type']=$recive['type'];
    	// $message['from']=$recive['from'];
    	// $message['to']=$recive['to'];
    	// $message['head']=$recive['head'];
    	// $message['message']=$recive['message'];
    	// $message['create_time']=time();
    	// Db::name('chat')->insert($message);
     //   Gateway::sendToUid($recive['to'],json_encode($message));
  
    }

 
    /**
     * onClose 事件回调 当用户断开连接时触发的方法
     *
     * @param  integer $client_id 断开连接的客户端client_id
     * @return void
     */
    public static function onClose($client_id)
    {
     //        $message['type']='logout';
    	// $message['list']=Gateway::getAllUidList();
     //   Gateway::sendToAll(json_encode($message));
    }


 
}
